package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSavaParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆，vehicleQuery={}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }


    @PostMapping("save")
    @ApiOperation("保存车辆")
    public JsonResult saveVehicle(VehicleSavaParam vehicleSaveParam) {
        log.debug("保存车辆信息,vehicleSaveParam={}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }


    @PostMapping("delete/{id}")
    @ApiOperation("删除车辆")
    public JsonResult deleteVehicle(@PathVariable Long id) {
        log.debug("删除车辆,id={}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{vehicleId}")
    @ApiOperation("解绑车辆")
    public JsonResult unbindVehicle(@PathVariable Long vehicleId) {
        log.debug("解绑车辆，vehicleId={}", vehicleId);
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geofenceId}/{vehicleId}")
    @ApiOperation("绑定车辆")
    public JsonResult bindVehicle(@PathVariable Long geofenceId, @PathVariable Long vehicleId) {
        log.debug("绑定车辆，geofenceId={},vehicleId={}", geofenceId, vehicleId);
        vehicleService.bindVehicle(geofenceId, vehicleId);
        return JsonResult.ok();
    }
}
